<%@ page import="java.io.*" %>
<%@ page import="DTO.LocaldataDTO" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Usercheck</title>
</head>
<body>
<jsp:useBean id="user" class="DTO.LocaldataDTO"/>
<jsp:useBean id="checkuser" class="DTO.LocaldataDTO"/>
<%
    File fRead=new File("User.txt");
    if(!fRead.exists()){
        //去注册页面
        String script = "<script>alert('用户名不存在，你去注册啊');location.href='Login.jsp'</script>";
        response.getWriter().println(script);
    }
    else {
    String [] arr=null;
    try {
        Reader in=new FileReader(fRead);
        BufferedReader bufferedRead=new BufferedReader(in);
        String str=bufferedRead.readLine();
        bufferedRead.close();
        in.close();
        arr = str.split("\\s+");
    }catch (IOException e){ }
    String str1=request.getParameter("userid");
    String str2=request.getParameter("password");
%>
<jsp:setProperty name="user" property="userid" value="<%=str1 %>"/>
<jsp:setProperty name="user" property="password" value="<%=str2 %>"/>
<jsp:setProperty name="checkuser" property="userid" value="<%=arr[0] %>"/>
<jsp:setProperty name="checkuser" property="password" value="<%=arr[1] %>"/>
<%
    if (user.getUserid().equals(checkuser.getUserid())&&user.getPassword().equals(checkuser.getPassword())){
        //跳转到homepage
        LocaldataDTO localdataDTO=new LocaldataDTO(arr[0],arr[1],arr[2],arr[3],arr[4]);
        request.getSession().setAttribute("localdataDTO",localdataDTO);
        response.sendRedirect("/HomePage.jsp");
    }
    else{
        //跳转到login
        String script = "<script>alert('用户名或密码错误，请重新登陆');location.href='Login.jsp'</script>";
        response.getWriter().println(script);
    }
    }
%>
</body>
</html>
